/**
 * 
 */
package com.greenx.core.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author u123199
 * 
 */
public final class Checker {
	private static Pattern validVINPattern = Pattern
			.compile("^[a-zA-Z0-9]{17}$");

	/**
	 * 
	 * @param v
	 *            a char of a vin
	 * @return result
	 */
	public static final boolean charChecker(char v) {
		boolean invalid = true;
		char temp = v;
		if (temp != 'a' && temp != 'b' && temp != 'c' && temp != 'd'
				&& temp != 'e' && temp != 'f' && temp != 'g' && temp != 'h'
				&& temp != 'j' && temp != 'k' && temp != 'l' && temp != 'm'
				&& temp != 'n' && temp != 'p' && temp != 'r' && temp != 's'
				&& temp != 't' && temp != 'u' && temp != 'v' && temp != 'w'
				&& temp != 'x' && temp != 'y' && temp != 'z' && temp != 'A'
				&& temp != 'B' && temp != 'C' && temp != 'D' && temp != 'E'
				&& temp != 'F' && temp != 'G' && temp != 'H' && temp != 'J'
				&& temp != 'K' && temp != 'L' && temp != 'M' && temp != 'N'
				&& temp != 'P' && temp != 'R' && temp != 'S' && temp != 'T'
				&& temp != 'U' && temp != 'V' && temp != 'W' && temp != 'X'
				&& temp != 'Y' && temp != 'Z' && temp != '1' && temp != '2'
				&& temp != '3' && temp != '4' && temp != '5' && temp != '6'
				&& temp != '7' && temp != '8' && temp != '9' && temp != '0') {
			invalid = false;
		}

		return invalid;
	}

	/**
	 * odometer value must look like a number
	 * 
	 * @param odometer
	 */
	public final void validateOdometer(final String odometer) {

		if (odometer == null || "".equals(odometer.trim())) {
			return;
		}

		try {

			Double.parseDouble(odometer);

		} catch (NumberFormatException nfe) {

		}
	}

	/**
	 * Validate VIN
	 * 
	 * <ul>
	 * <li>VIN must be 17 characters long
	 * <li>VIN must not contain any space or special character
	 * <ul/>
	 * 
	 * @param vin
	 * @return
	 */
	public static boolean validateVIN(final String vin) {

		if (vin == null) {
			return false;
		}

		Matcher mathcer = validVINPattern.matcher(vin);
		return mathcer.matches();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		boolean match = validateVIN("1G4HD57268U139156");

		System.out.println(match);
		String str = null;
		System.out.println(str);

	}

}
